#include "order_widget_ui.h"
#include <QFrame>

OrderWidgetUI::OrderWidgetUI(QWidget *parent)
    : QWidget(parent)
{
    setupUi();
}

void OrderWidgetUI::setupUi()
{
    setWindowTitle("订单中心");

    // 创建容器和网格布局
    QFrame *container = new QFrame(this);
    container->setFrameShape(QFrame::StyledPanel);
    container->setLineWidth(2);
    gridLayout = new QGridLayout(container);

    int row = 0;

    // 添加表头
    QLabel *headerImage = new QLabel("商品图片");
    QLabel *headerName = new QLabel("姓名");
    QLabel *headerPrice = new QLabel("价格");
    QLabel *headerQuantity = new QLabel("数量");

    gridLayout->addWidget(headerImage, row, 0);
    gridLayout->addWidget(headerName, row, 1);
    gridLayout->addWidget(headerPrice, row, 2);
    gridLayout->addWidget(headerQuantity, row, 3);
    ++row;

    QLabel *label_5 = new QLabel("订单号：");
    gridLayout->addWidget(label_5, row + 1, 0);
    QLabel *label_9 = new QLabel("label_9");
    gridLayout->addWidget(label_9, row + 1, 1);

    QLabel *label_6 = new QLabel("创建时间：");
    gridLayout->addWidget(label_6, row + 2, 0);
    QLabel *label_10 = new QLabel("label_10");
    gridLayout->addWidget(label_10, row + 2, 1);

    QLabel *label_7 = new QLabel("收货地址：");
    gridLayout->addWidget(label_7, row + 3, 0);
    QLabel *label_11 = new QLabel("label_11");
    gridLayout->addWidget(label_11, row + 3, 1);

    QLabel *label_8 = new QLabel("总金额：");
    gridLayout->addWidget(label_8, row + 4, 0);
    label_12 = new QLabel();
    label_12->setStyleSheet("QLabel { color: red; }");
    gridLayout->addWidget(label_12, row + 4, 1);

    QVBoxLayout *mainLayout = new QVBoxLayout(this);
    mainLayout->addStretch();
    mainLayout->addWidget(container);
    mainLayout->addStretch();
    setLayout(mainLayout);
}

void OrderWidgetUI::addProductInfo(QGridLayout *layout,
                                   int &row,
                                   const QString &imagePath,
                                   const QString &name,
                                   double price,
                                   int quantity)
{
    QLabel *imageLabel = new QLabel;
    QPixmap pixmap(imagePath);
    QPixmap scaledImage = pixmap.scaled(100, 150, Qt::KeepAspectRatio, Qt::SmoothTransformation);
    imageLabel->setPixmap(scaledImage);
    layout->addWidget(imageLabel, row, 0);

    QLabel *nameLabel = new QLabel(name);
    nameLabel->setStyleSheet("QLabel { font-size: 16px; font-weight: bold; }");
    layout->addWidget(nameLabel, row, 1);

    QLabel *priceLabel = new QLabel(QString::number(price, 'f', 2));
    priceLabel->setStyleSheet("QLabel { color: red; }");
    layout->addWidget(priceLabel, row, 2);

    QLabel *quantityLabel = new QLabel(QString("x%1").arg(quantity));
    quantityLabel->setStyleSheet("QLabel { color: blue; }");
    layout->addWidget(quantityLabel, row, 3);

    ++row;
}

QLabel *OrderWidgetUI::getLabel12() const
{
    return label_12;
}

OrderWidgetUI::~OrderWidgetUI() {}
